Preview: Here's an example of that program you will make today!

  • Click Run first to start the program.
  • Now click on the stage to make a firework! How many can you have exploding at once?
  • Try changing the value of amount or speed (lines 9 and 10). What happens to the fireworks?

Click Run to see your changes, then Submit and Next when you're ready to start programming!

To navigate the page using the TAB key, first press ESC to exit the code editor.

def return_trajectory(speed, angle): radians = math.radians(angle) x_velocity = speed * math.cos(radians) y_velocity = speed * math.sin(radians) return (x_velocity, y_velocity) stage.set_background_color("black") amount = 10 speed = 5 color_list = ["purple", "yellow", "red"] stage.disable_all_walls() def click(): x = stage.click_x() y = stage.click_y() particle_list = [] for color in color_list: for counter in range(amount): sprite = codesters.Circle(x, y, 10, color) particle_list.append(sprite) sprite.pen_down() angle = 0 for count, p in enumerate(particle_list): count += 1 speed_values = return_trajectory(speed, angle) p.set_x_speed(speed_values[0]) p.set_y_speed(speed_values[1]) angle += 360/amount if count % amount == 0: stage.wait(.1) stage.wait(0.5) for p in particle_list: p.clear() stage.remove_sprite(p) # add other actions... stage.event_click(click) stage.set_gravity(3)
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)